package com.wujunshen.algorithm.leetcode.dynamic.programming;

/**
 * @author frank woo(吴峻申) <br>
 * email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/8/9 21:43<br>
 */
public class 买卖股票的最佳时机含手续费 {
    public int maxProfit(int[] prices, int fee) {
        int len = prices.length;
        if (len < 2) {
            return 0;
        }

        int dp0 = 0;
        int dp1 = Integer.MIN_VALUE;
        for (int price : prices) {
            //手里没股票
            dp0 = Math.max(dp0, dp1 + price);
            //手里有股票
            dp1 = Math.max(dp1, dp0-price-fee);
        }
        //返回没股票的时候
        return dp0;
    }
}
